package com.sparrow.common.ai.findpath;

import com.sparrow.common.object.Resettable;

import java.util.Objects;

public class PathNode implements Comparable<PathNode>, Resettable {
    public int x;
    public int y;
    public int h;
    public int g;
    public int f;

    public PathNode parent;

    public PathNode() {

    }

    public PathNode(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public void setParent(PathNode parent) {
        this.parent = parent;
    }

    public PathNode getParent() {
        return parent;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getF() {
        return f;
    }

    public void setF(int f) {
        this.f = f;
    }

    public int getG() {
        return g;
    }

    public void setG(int g) {
        this.g = g;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PathNode)) return false;
        PathNode other = (PathNode) o;
        return this.x == other.x && this.y == other.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }

    @Override
    public int compareTo(PathNode o) {
        return this.getF() - o.getF();
    }

    @Override
    public String toString() {
        return "{" +
                "x=" + x +
                ", y=" + y +
                ", f=" + f +
                ", g=" + g +
                '}';
    }

    @Override
    public void reset() {
        this.x = 0;
        this.y = 0;
        this.g = 0;
        this.h = 0;
        this.f = 0;
        this.parent = null;
    }
}
